package cc.momas.v2;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Sod-Momas
 * @since 2020/11/22
 */
public class SimpleTokenReader implements TokenReader {
    public List<Token> tokenList;
    public int index;

    public SimpleTokenReader(List<Token> tokenList) {
        this.tokenList = tokenList;
    }

    @Override
    public Token next() {
        return tokenList.get(++index);
    }

    @Override
    public Token prev() {
        if (0 <= index) {
            return tokenList.get(--index);
        }
        return null;
    }

    @Override
    public Token get(int index) {
        return tokenList.get(index);
    }

    @Override
    public int index() {
        return index;
    }

    @Override
    public int reset(int index) {
        int cur = this.index;
        this.index = index;
        return cur;
    }
}
